#include "InformationManager.h"

#include "..\Util.h"

namespace BroodWar
{
	namespace Addon
	{
		InformationManager::InformationManager()
		{
			instance = BWSAL::InformationManager::create();
		}
		
		InformationManager::~InformationManager()
		{
			BWSAL::InformationManager::destroy();
		}
		
		InformationManager::!InformationManager()
		{
			BWSAL::InformationManager::destroy();
		}

		InformationManager^ InformationManager::Instance::get()
		{
			if(s_instance == nullptr)
				s_instance = gcnew InformationManager();
			return s_instance;
		}

		void InformationManager::OnUnitDiscover(Unit^ unit)
		{
			instance->onUnitDiscover(ConvertUnit(unit));
		}
		
		void InformationManager::OnUnitEvade(Unit^ unit)
		{
			instance->onUnitEvade(ConvertUnit(unit));
		}
		
		void InformationManager::OnUnitDestroy(Unit^ unit)
		{
			instance->onUnitDestroy(ConvertUnit(unit));
		}

		Player^ InformationManager::GetPlayer(Unit^ unit)
		{
			return ConvertPlayer(instance->getPlayer(ConvertUnit(unit)));
		}
		
		Api::UnitType^ InformationManager::GetType(Unit^ unit)
		{
			return ConvertUnitType(instance->getType(ConvertUnit(unit)));
		}
		
		Position^ InformationManager::GetLastPosition(Unit^ unit)
		{
			return ConvertPosition(instance->getLastPosition(ConvertUnit(unit)));
		}
		
		int InformationManager::GetLastSeenTime(Unit^ unit)
		{
			return instance->getLastSeenTime(ConvertUnit(unit));
		}
		
		bool InformationManager::Exists(Unit^ unit)
		{
			return instance->exists(ConvertUnit(unit));
		}
		
		bool InformationManager::EnemyHasBuilt(Api::Enum::UnitType type)
		{
			return instance->enemyHasBuilt(ConvertUnitType(type));
		}
		
		int InformationManager::GetBuildTime(Api::Enum::UnitType type)
		{
			return instance->getBuildTime(ConvertUnitType(type));
		}
		
		HashSet<BaseLocation^>^ InformationManager::EnemyBases::get()
		{
			return ToHashSet<BWTA::BaseLocation*, BaseLocation^>(instance->getEnemyBases(), &ConvertBaseLocation);
		}
		
		void InformationManager::SetBaseEmpty(BaseLocation^ base)
		{
			instance->setBaseEmpty(ConvertBaseLocation(base));
		}
	}
}
